/* jshint esversion: 6 */
export function debounce(fn, interval = 300) {
    let timeout = null;
    return function () {
        clearTimeout(timeout);
        timeout = setTimeout(() => {
            fn.apply(this, arguments);
        }, interval);
    };
}

let target = '';
export function deepFind(arr,id){
    if(arr){
        for(let i=0;i<arr.length;i++) {
            if(arr[i].id === id) {
                target = arr[i];
                break;
            }else{
                target = ''
            }
               if(arr[i].deptList){
                   deepFind(arr[i].deptList,id)
               }
        }
       return target
    } else {
        return ''
    }
}
export function clear(data) {
    Object.keys(data).forEach(item=>{
            data[item] = '';
        });
}
export function getArray(arr,children = 'deptList') {
    let arrs = [];
    for(let i=0;i<arr.length;i++) {
        arrs.push(arr[i]);
        if(arr[i][children]){
            arrs = arrs.concat(getArray(arr[i][children],children))
        }

    }
    return arrs;
}

export function getChecked(arr) {
    let arrs = [];
    for(let i=0;i<arr.length;i++){
        if(arr[i].checked) {
            arrs.push(arr[i].id)
        }
        if(arr[i].aclList){
            arrs = arrs.concat(getChecked(arr[i].aclList));
        }
    }
    return arrs;
}
export const baseURL = process.env.NODE_ENV === 'production' ? 'https://iel-api.sh-inline.com' : 'http://192.168.50.102:8080';

export function getFileName(name) {
    return name.replace(/(.*\/)*([^.]+).*/ig,"$2") + '.' + name.substring(name.lastIndexOf('.') + 1);
}